//
//  ZYCCicleFriendsPlainDetailTextViewController.m
//  ZDSC
//
//  Created by ZDTX on 2021/9/19.
//

#import "ZYCCicleFriendsPlainDetailTextViewController.h"
#import "NSDateExtra.h"
#import "ZYCCicleFriendsPlainDetailTextView.h"
#import "ZYCCycleFriendModel.h"
#import "ZYCLoginOutView.h"

@interface ZYCCicleFriendsPlainDetailTextViewController ()<ZYCLoginOutViewDelegate>
@property (nonatomic, strong) UIButton *deleteButton;
@property (nonatomic, strong) ZYCLoginOutView *loginOutView;

@property (nonatomic, strong) ZYCCicleFriendsPlainDetailTextView *detailView;
@end

@implementation ZYCCicleFriendsPlainDetailTextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = [NSDateExtra getDateStringWithDateString:self.model.uploadTime currenDateFormat:@"yyyy-MM-dd HH:mm:ss" dateFormat:@"yyyy年MM月dd日 HH:mm"];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.deleteButton];
    [self.view addSubview:self.detailView];
    self.detailView.model = self.model;
}

- (UIButton *)deleteButton{
    if (!_deleteButton) {
        _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_deleteButton setTitle:@"删除" forState:UIControlStateNormal];
        [_deleteButton setTitleColor:HEX_RGB(@"FFFFFF") forState:UIControlStateNormal];
        [_deleteButton addTarget:self action:@selector(clickDeleteAction:) forControlEvents:UIControlEventTouchUpInside];
        _deleteButton.titleLabel.font  = kCustomFont(@"PingFangSC-Regular", 18.0f);
    }
    return _deleteButton;
}


#pragma mark - ZYCLoginOutViewDelegate

- (void)loginOutViewDidClickLogout{
    NSDictionary *params = @{
        @"growReportId":self.model.growReportId
    };
    [[URLManager sharedURLManager] postUrlString:Appliance_Post_GrowthDelete requestService:RequestServiceWorkBench parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
            
        } success:^(id  _Nullable responseObject) {
            if (SUCCESS(responseObject[@"code"])) {
                [MrjToast makeToast:responseObject[@"body"] makeView:self.view];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self.navigationController popViewControllerAnimated:YES];
                });
            }else{
                [MrjToast makeToast:responseObject[@"message"] makeView:self.view];
            }
        } failure:^(NSError * _Nonnull error) {
            
        }];
}


- (ZYCLoginOutView *)loginOutView {
    if (!_loginOutView) {
        _loginOutView = [[ZYCLoginOutView alloc] initWithFrame:CGRectMake(0, 0, 280.0f, 155.0f)];
        _loginOutView.delegate = self;
        _loginOutView.title = @"温馨提示";
        _loginOutView.content = @"要删除该成长记录吗?";
        [self.navigationController.view addSubview:_loginOutView];
    }
    return _loginOutView;
}


- (void)clickDeleteAction:(UIButton *)sender{
    
    [self.loginOutView show];

}


- (ZYCCicleFriendsPlainDetailTextView *)detailView {
    if (!_detailView) {
        _detailView = [[ZYCCicleFriendsPlainDetailTextView alloc] initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight - kNavBarAndStatusBarHeight)];
    }
    return _detailView;
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
